package binfa;

import java.util.concurrent.*;

//自定义线程池
public class Executor {
    public static void main(String[] args) {
        ThreadPoolExecutor t=new ThreadPoolExecutor(2,3,2, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(1),new ThreadPoolExecutor.DiscardPolicy());
       //使用系统自带的四种
        ExecutorService e1=Executors.newSingleThreadExecutor();
        ExecutorService e2=Executors.newFixedThreadPool(3);
        for(int i=0;i<10;i++){
            myRun m=new myRun();
////            t.execute(m);

//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            e1.execute(m);
            e2.execute(m);
        }
        t.shutdown();
        System.out.println("线程池结束");
    }
}

class  myRun implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程池执行情况");
    }
}